/*
 * \brief  Pistachio-specific thread helper functions
 * \author Julian Stecklina
 * \date   2008-02-20
 */

/*
 * Copyright (C) 2008-2009 Julian Stecklina
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__PISTACHIO__THREAD_HELPER_H_
#define _INCLUDE__PISTACHIO__THREAD_HELPER_H_

#include <base/printf.h>

namespace Pistachio
{
#include <l4/types.h>

	/*
	 * Pistachio has no server-defined badges for page-fault messages.
	 * Therefore, we have to interpret the sender ID as badge.
	 */
	inline unsigned long convert_l4_threadid_to_badge(L4_ThreadId_t tid) {
		return tid.raw; }

	inline void print_l4_threadid(L4_ThreadId_t t)
	{
		if (L4_IsLocalId(t)) {
			Genode::printf("THREAD (local) %02x\n",
			               t.local.X.local_id);

		} else if (L4_IsGlobalId(t)) {
			Genode::printf("THREAD (global) %02x (version %x)\n",
			                t.global.X.thread_no,
			                t.global.X.version);

		} else {
			const char *name;

			if (t == L4_nilthread) name = "nilthread";
			else if (t == L4_anythread) name = "anythread";
			else name = "???";

			Genode::printf("THREAD (%s)\n", name);
		}
	}
}

#endif /* _INCLUDE__PISTACHIO__THREAD_HELPER_H_ */
